#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
批量处理NER示例脚本
展示如何使用batch_process_ner.py处理文本文件
"""

import subprocess
import sys
import os

def run_batch_process():
    """
    运行批量处理示例
    """
    print("开始批量处理示例...")
    
    # 检查输入文件是否存在
    if not os.path.exists("trans.txt"):
        print("错误: trans.txt 文件不存在")
        return
    
    # 方法1: 使用命令行参数
    print("\n方法1: 使用命令行参数运行批量处理")
    cmd = [
        sys.executable, 
        "batch_process_ner.py", 
        "trans.txt",
        "-o", "results",
        "-d", "manufacturing"
    ]
    
    try:
        result = subprocess.run(cmd, capture_output=True, text=True, timeout=120)
        if result.returncode == 0:
            print("批量处理完成!")
            print(result.stdout)
        else:
            print("批量处理出错:")
            print(result.stderr)
    except subprocess.TimeoutExpired:
        print("处理超时")
    except Exception as e:
        print(f"运行批处理时出错: {e}")
    
    # 方法2: 直接在代码中使用类
    print("\n方法2: 直接在代码中使用BatchNERProcessor类")
    
    try:
        from batch_process_ner import BatchNERProcessor
        
        # 创建处理器实例
        processor = BatchNERProcessor("http://192.168.224.255:5000")
        
        # 处理文件
        processor.process_file("trans.txt", "results_direct", "manufacturing")
        
        print("直接调用处理完成!")
        
    except ImportError as e:
        print(f"导入BatchNERProcessor时出错: {e}")
    except Exception as e:
        print(f"直接调用处理时出错: {e}")

if __name__ == "__main__":
    run_batch_process()